package datatypes;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DutyDate {

	public Calendar date;

	// starting hour in minutes
	public Date startingDate;

	// ending hour in minutes
	public Date endingDate;

	public DutyDate(int year, int month, int day, Date startingDate,
			Date endingDate) {
		date = new GregorianCalendar(year, month, day);
		this.startingDate = startingDate;
		this.endingDate = endingDate;
	}

	public DutyDate(Date startingDate, Date endingDate) {
		date = null;
		this.startingDate = startingDate;
		this.endingDate = endingDate;
	}

	public void setDay(int day) {
		date.set(Calendar.DAY_OF_WEEK, day);
	}

	public void setMonth(int month) {
		date.set(Calendar.MONTH, month);
	}

	public void setYear(int year) {
		date.set(Calendar.YEAR, year);
	}

	public Date getEndingDate() {
		return this.endingDate;
	}

	public Date getStartingDate() {
		return this.startingDate;
	}

	public void setEndingDate(Date endingDate) {
		this.endingDate = endingDate;
	}

	public void setStartingDate(Date startingDate) {
		this.startingDate = startingDate;
	}

	public void setDate(Calendar date) {
		this.date = date;
	}

	public Calendar getDate() {
		return this.date;
	}

	public static String BuildReadableDate(Date fromDate, Date toDate) {
		return pad(fromDate.getHours()) + " : " + pad(fromDate.getMinutes())
				+ " - " + pad(toDate.getHours()) + " : "
				+ pad(toDate.getMinutes());
	}

	private static String pad(int c) {
		if (c >= 10)
			return String.valueOf(c);
		else
			return "0" + String.valueOf(c);
	}

}
